#ifndef __HAL_H__
#define __HAL_H__



//================================================================
//
//================================================================
#define HAL_MONITOR_OUTPUT_HIGH()		CSP_GPIO_OutputHigh(GPIO_D, PIN_10)	
#define HAL_MONITOR_OUTPUT_LOW()		CSP_GPIO_OutputLow(GPIO_D, PIN_10)	

#define HAL_MONITOR_PD11_OUTPUT_HIGH()	CSP_GPIO_OutputHigh(GPIO_D, PIN_11)	
#define HAL_MONITOR_PD11_OUTPUT_LOW()	CSP_GPIO_OutputLow(GPIO_D, PIN_11)	

#define HAL_MONITOR_PD12_OUTPUT_HIGH()	CSP_GPIO_OutputHigh(GPIO_D, PIN_12)	
#define HAL_MONITOR_PD12_OUTPUT_LOW()	CSP_GPIO_OutputLow(GPIO_D, PIN_12)	
//----------------------------------------------------------------------------------
#define HAL_MONITOR_PD13_OUTPUT_HIGH()	CSP_GPIO_OutputHigh(GPIO_D, PIN_13)	
#define HAL_MONITOR_PD13_OUTPUT_LOW()	CSP_GPIO_OutputLow(GPIO_D, PIN_13)	

#define HAL_MONITOR_PD14_OUTPUT_HIGH()	CSP_GPIO_OutputHigh(GPIO_D, PIN_14)	
#define HAL_MONITOR_PD14_OUTPUT_LOW()	CSP_GPIO_OutputLow(GPIO_D, PIN_14)	

#define HAL_MONITOR_PD15_OUTPUT_HIGH()	CSP_GPIO_OutputHigh(GPIO_D, PIN_15)	
#define HAL_MONITOR_PD15_OUTPUT_LOW()	CSP_GPIO_OutputLow(GPIO_D, PIN_15)	





//================================================================
// UART
//================================================================
#define HAL_UART_ENABLE_TX_INTR(channel, status)		do { (status) ? \
														CSP_UART_SET_UnIER(channel, (CSP_UART_GET_UnIER(channel) | UnIER_THREIE)) :\
														CSP_UART_SET_UnIER(channel, (CSP_UART_GET_UnIER(channel) & ~UnIER_THREIE)); } while(0)


#define HAL_UART_IS_LINE_ERROR(channel)					(CSP_UART_GET_UnLSR(channel) & (UnLSR_BI|UnLSR_FE|UnLSR_PE|UnLSR_OE))

#define HAL_UART_CLEAR_LINE_ERROR(channel, status)		(status = CSP_UART_GET_UnLSR(channel))

#define HAL_UART_IS_TX_READY(channel)					((CSP_UART_GET_UnLSR(channel) & UnLSR_THRE) == (UnLSR_THRE))




//================================================================
// SPI
//================================================================
#define HAL_SPI_WRITE_DATA(spi, data)					CSP_SPI_SET_SPnTDR(spi, data)

#define HAL_SPI_ENABLE(spi)								CSP_SPI_SET_SPnEN(spi, 1); 
#define HAL_SPI_DISABLE(spi)							CSP_SPI_SET_SPnEN(spi, 0); 

//#define HAL_SPI_BUFFER_CLEAR(spi)						CSP_SPI_SET_SPnCR(spi, (CSP_SPI_GET_SPnCR(spi) | SPnCR_TXBC))
#define HAL_SPI_BUFFER_CLEAR(spi)						CSP_SPI_SET_SPnCR(spi, (CSP_SPI_GET_SPnCR(spi) | (SPnCR_TXBC|SPnCR_RXBC)))


#define HAL_SPI_LOAD_FIRST_DATA(spi)					CSP_SPI_SET_SPnCR(spi, (CSP_SPI_GET_SPnCR(spi) | SPnCR_TXBC))
#define HAL_SPI_IS_FIRST_DATA_NOT_LOADED(spi)			(CSP_SPI_GET_SPnCR(spi) & SPnSR_TRDY)




//================================================================
// I2C
//================================================================
#define HAL_I2C_LOAD_ADDR(twi, addr)					CSP_I2C_SET_ICnDR(twi, addr)
#define HAL_I2C_START(twi)								CSP_I2C_SET_ICnCR(twi,( CSP_I2C_GET_ICnCR(twi) | (ICnCR_START|ICnCR_ACKEN)))



//#########################################################################
//#
//#		D M A
//#
//#########################################################################



#endif 

